package com.whub507.msgmanager.controller;

import com.whub507.msgmanager.common.Field;
import com.whub507.msgmanager.common.ResResult;
import com.whub507.msgmanager.domain.Model;
import com.whub507.msgmanager.mapper.ModelMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.License;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
@CrossOrigin
@Api(tags = "模板接口")
@RequestMapping("/model")
public class ModelController {

    @Resource
    private ModelMapper modelMapper;

    @GetMapping("/allType")
    @ApiOperation(value = "获取所有模版类型")
    public ResResult<List<String>> getAllType(){

        List<String> list = modelMapper.selectAllType();

        return ResResult.ok(list, null, "返回所有类型名");
    }

    @GetMapping("/getModel")
    @ApiOperation(value = "获取对应模板类型名的模板")
    public ResResult<List<Model>> getByType(String type){
        List<Field> fields = new ArrayList<>();
        fields.add(new Field("type","类型"));
        fields.add(new Field("content","内容"));
        return ResResult.ok(modelMapper.selectByType(type), fields,"返回该类型下的所有模板");
    }

}
